{extend name="public:_base" /}
{block name="css"}
<link rel="stylesheet" type="text/css" href="__STATIC__/admin/uploadify/uploadify.css">
{/block}
{block name="js"}
{load href="__STATIC__/admin/hui/lib/My97DatePicker/4.8/WdatePicker.js" /}
<script src="/tpl/static/artDialog/jquery.artDialog.js?skin=default"></script>
<script src="/tpl/static/artDialog/plugins/iframeTools.js"></script>
{load href="__STATIC__/admin/login/js/jquery-1.4.2.min.js" /}
{include file="public/_validform"}
<!--上传配置 -->
<script src="__STATIC__/admin/js/upfile.js" type="text/javascript"></script>

<!-- 配置文件 -->
<script type="text/javascript" src="__STATIC__/admin/hui/lib/ueditor/1.4.3/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="__STATIC__/admin/hui/lib/ueditor/1.4.3/ueditor.all.js"></script>

<script type="text/javascript">
    var ue = UE.getEditor('editor');
    $("[name='cid']").find("[value='{$data.cid ?? ''}']").attr("selected", true);
    $("[name='cid']").find("[value='{$data.cid ?$data.cid :$Request.param.addcid }']").attr("selected", true);

    upload_image('image', '', '300', '300', '500');
    var URL = {
        uploader: '{:url('Upload / image
    ')}',
        swf
    :
    '__STATIC__/admin/uploadify/uploadify.swf',
        ROOT
    :
    '__PUBLIC__/uploads/image',
    }
    $(document).ready(function (e) {
        //dateformat(7);
        number();
        $("#submit_survey").click(function () {
            var cid = $('#contentid').val();
            var title = $('#questionnaire_til').val();
            if (title == '您可以在这里创建您的考试题目，同时对考试活动加以说明') {
                title = '';
            }
            if (title == '') {
                alert('请填写考试标题');
                return false;
            }
            save_survey();
            return false;
        });

        $(".del").live("click", function () {
            delimage($(this));
        });

        $(".optionul li .pic").live('mouseenter', function () {
            $(this).children("img").show();
        });

        $(".optionul li .pic").live('mouseleave', function () {
            $(this).children("img").hide();
        });

        /*投票截至时间*/
        $(".activity_list li .up_select").click(function () {
            $(this).children("div").show();
        });

        $(".activity_list li .up_select div").mouseleave(function () {
            $(this).hide();
        });

        $(".activity_list li .up_select div a").live("click", function () {
            var t = $(this).text();
            $(".activity_list li .up_select div").hide();
            $(".activity_list li .up_select u").text(t);
            $(".activity_list li .up_time").hide();
        });
    });

    function delimage(obj) {
        obj.parent().addClass("hidden");
        obj.parent().prev("span").removeClass("hidden");
        obj.parent().parent().find("input[class='image_class']").val("");
    }

    function save_survey() {
        $.post("{:url('Research/saveInfo')}", $('#survey_form').serialize(), function (response) {
            if (response.error_code) {
                alert(response.msg);
                return false;
            } else {
                location.href = "{:url('Research/index')}";
                return false;
            }
        }, 'json');
    }

    function clear_form() {
        $("input").val('');
        $("textarea").val('');
        $("select").val('');
        $("#infotype").val(3);
        $("#tag_image_show").hide();
        $("#explanation").hide();
    }

    /*添加选项*/
    function number() {
        var i = 0;
        $(".optionul li").each(function () {
            $(this).find("input[name='userfile']").attr("id", "userfile_" + i).live("change", function () {
                uploadimage($(this).attr("id"));
            });
            i++;
        })
    }

    $(".orange_tips a.close").click(function () {
        $(".orange_tips").remove();
    })

    /*添加选项*/
    var a = new Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");

    function letters() {
        $(".question_box ul li").each(function () {
            $(this).find("span:first").html(a[$(this).index()]);
            $(this).find(".question").attr('name', 'oldquestion[' + $(this).parent().attr('id') + '][' + $(this).index() + ']').val(a[$(this).index()]);
            $(this).find(".txt").attr('name', 'option[' + $(this).parent().attr('id') + '][' + $(this).index() + ']');
            $(this).find(".hide_txt").attr('name', 'oid[' + $(this).parent().attr('id') + '][' + $(this).index() + ']');
            $(this).find(".image_class").attr('name', 'image[' + $(this).parent().attr('id') + '][' + $(this).index() + ']');
        });
        $(".topic_box .question_box").each(function () {
            // 问题序号 $(this).find(".question_info span u").html($(this).index() + 1);
            $(this).find(".question_info span u").html($(this).index());
        });
        $('#question_info_1 .box_del').remove();
        $('.question_box ul li .txt').focus(function () {
            $(this).next().show();
        });

    }

    letters();
    //
    // $(".question_box ul li .list_del").live('click',function(){
    //     $(this).parents("li").remove();
    //     letters();
    // });
    //
    //
    // $(".question_box .bot_add a.btnGrayS").live('click',function(){
    //     var t = '<li><span>A</span><u>选项：</u><input type="hidden" class="hide_txt"> <input type="text" class="txt"/><input type="hidden" class="image_class" /> <a class="list_del" href="javascript:;" title="删除这个选项">×</a><span class="no_pic hidden"><a href="javascript:;" class="up"><i></i>插入图片<input type="file" name="userfile" title="图片建议尺寸：150*100" alt="图片建议尺寸：150*100"></a><div class="uppic_prompt">图片建议尺寸：<span>150*100</span><div class="caret_Up"><em>◆</em><span>◆</span></div></div></span><span class="pic hidden" style="width:auto"><a href="javascript:;">../fjdskjf.jpg</a><img src="" width="150" height="100"><a href="javascript:;" class="del">×</a></span></li>';
    //     if($(this).parents(".question_box").find("ul li").size() <= 25){
    //         $(this).parents(".question_box").find("ul").append(t);
    //         letters();
    //         number();
    //     }else{
    //         alert("您添加的数量够您用一辈子了！");
    //     }
    // })
    /*添加选项结束*/

    /* 判断是否自由题,隐藏相关信息 */
    $(".typeselect").each(function () {
        var showTypeselect = $(this).find("option:selected").val();
        if( showTypeselect =="2" ){
            $(this).parent().parent().find(".optionul").css("display","none");
            $(this).parent().parent().find(".bot_add").css("display","none");
        } else {
            $(this).parent().parent().find(".optionul").css("display","block");
            $(this).parent().parent().find(".bot_add").css("display","block");
        }
    });

    /* 添加内容 开始判断是否是自由题 */
    function typeselect() {
        $(".typeselect").change(function(){
            var selectval = $(this).val();
            if( selectval=="2" ){
                $(this).parent().find("input.answer").css("display","none");
                $(this).parent().parent().find(".optionul").css("display","none");
            } else {
                $(this).parent().find("input.answer").css("display","block");
                $(this).parent().parent().find(".optionul").css("display","block");
            }
        });
    }

    typeselect();

    /*添加题目和删除题目*/
    $(".add_questio a").click(function () {
        var t = '<div class="question_box ques_box"><p class="question_info"><span>问题<u>1</u>：</span><input type="text" class="txt" value="请填写问题的题目" />'
            + '<input type="text" class="answer" value="" placeholder="请填写题目的答案" onkeyup="value=value.replace(/[^a-dA-D]/g,\'\');">'
            + '<input type="checkbox" class="checkd" value="1" style="display: none;" /><input type="hidden" class="hide_qid" id="qid[1]" name="qid[1]"><label style="display: none"> 允许多选</label><input type="number" class="point" placeholder="请填写题目分数"><select class="typeselect"><option value="0">单选</option><option value="1">多选</option><option value="2">自由填写</option></select><a href="javascript:;" class="box_del">×删除</a></p>'
            + '<span class="insert_pic hidden">图片建议尺寸：150*100</span><ul id="1" class="optionul">'
            + '<li><span>A</span><u>选项：</u><input type="hidden" class="question"><input type="hidden" class="hide_txt"> <input type="text" class="txt" /><input type="hidden" class="image_class" /> <a class="list_del" href="javascript:;" title="删除这个选项" style="display: none;">×</a><span class="no_pic hidden"><a href="javascript:;" class="up"><i></i>插入图片<input type="file" name="userfile" title="图片建议尺寸：150*100" alt="图片建议尺寸：150*100"></a><div class="uppic_prompt">图片建议尺寸：<span>150*100</span><div class="caret_Up"><em>◆</em><span>◆</span></div></div></span><span class="pic hidden" style="width:auto"><a href="javascript:;">../fjdskjf.jpg</a><img src="" width="150" height="100"><a href="javascript:;" class="del">×</a></span></li>'
            + '<li><span>B</span><u>选项：</u><input type="hidden" class="question"><input type="hidden" class="hide_txt" > <input type="text" class="txt" /><input type="hidden" class="image_class" /> <a class="list_del" href="javascript:;" title="删除这个选项" style="display: none;">×</a><span class="no_pic hidden"><a href="javascript:;" class="up"><i></i>插入图片<input type="file" name="userfile" title="图片建议尺寸：150*100" alt="图片建议尺寸：150*100"></a><div class="uppic_prompt">图片建议尺寸：<span>150*100</span><div class="caret_Up"><em>◆</em><span>◆</span></div></div></span><span class="pic hidden" style="width:auto"><a href="javascript:;">../fjdskjf.jpg</a><img src="" width="150" height="100"><a href="javascript:;" class="del">×</a></span></li>'
            + '<li><span>C</span><u>选项：</u><input type="hidden" class="question"><input type="hidden" class="hide_txt" > <input type="text" class="txt" /><input type="hidden" class="image_class" /> <a class="list_del" href="javascript:;" title="删除这个选项" style="display: none;">×</a><span class="no_pic hidden"><a href="javascript:;" class="up"><i></i>插入图片<input type="file" name="userfile" title="图片建议尺寸：150*100" alt="图片建议尺寸：150*100"></a><div class="uppic_prompt">图片建议尺寸：<span>150*100</span><div class="caret_Up"><em>◆</em><span>◆</span></div></div></span><span class="pic hidden" style="width:auto"><a href="javascript:;">../fjdskjf.jpg</a><img src="" width="150" height="100"><a href="javascript:;" class="del">×</a></span></li>'
            + '<li><span>D</span><u>选项：</u><input type="hidden" class="question"><input type="hidden" class="hide_txt" > <input type="text" class="txt" /><input type="hidden" class="image_class" /> <a class="list_del" href="javascript:;" title="删除这个选项" style="display: none;">×</a><span class="no_pic hidden"><a href="javascript:;" class="up"><i></i>插入图片<input type="file" name="userfile" title="图片建议尺寸：150*100" alt="图片建议尺寸：150*100"></a><div class="uppic_prompt">图片建议尺寸：<span>150*100</span><div class="caret_Up"><em>◆</em><span>◆</span></div></div></span><span class="pic hidden" style="width:auto"><a href="javascript:;">../fjdskjf.jpg</a><img src="" width="150" height="100"><a href="javascript:;" class="del">×</a></span></li>'
            + '</ul><p class="bot_add" style="display:none"><a href="javascript:;" class="btnGrayS vm bigbtn"><i class="Hui-iconfont">&#xe600;</i>再添加一个选项</a></p></div>';
        $(".add_questio").before(t);
        $(".question_box:last").find("li:eq(3)").nextAll().remove();
        $(".question_box").each(function () {
            //$(this).find("u").html($(this).index());
            $(this).find(".question_info .txt").attr('name', 'question[' + $(this).index() + ']');
//            $(this).find(".question_info .checkd").attr('name', 'ismulti['+$(this).index()+']');
            $(this).find(".question_info .answer").attr('name', 'answer[' + $(this).index() + ']');
            $(this).find(".question_info .typeselect").attr('name', 'ismulti[' + $(this).index() + ']');
            $(this).find(".question_info .point").attr('name', 'point[' + $(this).index() + ']');
            $(this).find(".question_info .checkd").attr('id', 'ismulti_' + $(this).index());
            $(this).find(".question_info label").attr('for', 'ismulti_' + $(this).index());
            $(this).find(".question_info .hide_qid").attr('name', 'qid[' + $(this).index() + ']');
            $(this).find("ul").attr('id', $(this).index());
        });
        letters();
        number();

        typeselect();
    })
    $(".box_del").live('click', function () {
        $(this).parents(".question_box").remove();
        $(".question_box").each(function () {
            //$(this).find("u").html($(this).index());
        });
        letters();
        number();
    })
    /*添加题目和删除题目结束*/

    /*input默认文字显示、消失*/
    $("#questionnaire_til").focusin(function () {
        if ($(this).val() == "您可以在这里创建您的考试题目，同时对考试活动加以说明") {
            $(this).val("");
            $(this).css("color", "#666");
        }
    }).focusout(function () {
        if ($(this).val() == "") {
            $(this).val("您可以在这里创建您的考试题目，同时对考试活动加以说明");
            $(this).css("color", "#999");
        }
    })
    $(".question_box p .txt").live('focusin', function () {
        if ($(this).val() == "请填写问题的题目") {
            $(this).val("");
            $(this).css("color", "#666");
        }
    }).live('focusout', function () {
        if ($(this).val() == "") {
            $(this).val("请填写问题的题目");
            $(this).css("color", "#999");
        }
    });


    function dateformat(day) {
        var date = new Date();
        date.setDate(date.getDate() + day);
        var deadline = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
        $("#deadline").val(deadline);
    }
</script>
{/block}
{block name="main"}
<div class="page-container">

    <form class="form form-horizontal" action="{:url(\''.\\think\\Request::instance()->controller().'/save')}" id="form" method="post">

        <table class="table table-border table-bordered table-bg table-style">
            <thead>
                <tr>
                    <th colspan="2" scope="col">填写信息</th>
                </tr>
            </thead>

            <tbody>
            {include file="public:_navadd"}
            <tr>
                    <th>考试标题：</th>
                    <td>
                        <input type="text" class="input-text" id="questionnaire_til" name="title" value="{$data.title ?? ''}" placeholder="您可以在这里创建您的考试题目，同时对考试活动加以说明">
                    </td>
                </tr>

                <tr>
                    <th>关键词：</th>
                    <td>
                        <input type="text" class="input-text" id="keyword" name="keyword" value="{$data.keyword ?? ''}">
                    </td>
                </tr>

                <tr>
                    <th>考试说明：</th>
                    <td>
                        <script id="editor" type="text/plain" name="description" style="width:100%;height:400px;">{$data.description|default=''|html_entity_decode ?? ''}</script>
                    </td>
                </tr>

                <tr>
                    <th>开始时间：</th>
                    <td>
                        <span class="up_time" style="width:150px;">
                            <u id="t">
                                <input type="text" value="{$data['starttime']}" id="starttime" style="margin-top:6px;width:125px;" name="starttime" class="input-text hasDatepicker" onClick="WdatePicker({dateFmt:'yyyy-MM-dd  HH:mm:ss'})">
                            </u>
                        </span>
                    </td>
                </tr>

                <tr>
                    <th>截至时间：</th>
                    <td>
                        <span class="up_time" style="width:150px;">
                            <u id="t">
                                <input type="text" value="{$data['dateline']}" id="deadline" style="margin-top:6px;width:125px;" name="dateline" class="input-text hasDatepicker" onClick="WdatePicker({dateFmt:'yyyy-MM-dd  HH:mm:ss'})">
                            </u>
                        </span>
                    </td>
                </tr>
            </tbody>
        </table>

        <!-- 选择问题 -->
        <div class="topic_box topic_kaoshi">

            <div class="question-title ques-ztitle">
                <div>问题序号</div>
                <div>填写问题题目</div>
                <div>
                    填写问题答案<br>(按照顺序来排列)
                </div>
                <div>填写题目分数</div>
                <div>单选，多选，自由题</div>
            </div>

            {volist name="list" id="ques" key="i"}
            <div class="question_box" id="question_info_{$i}">
                <p class="question_info">
                    <span>问题<u>{$i}</u>：</span>
                    <input type="text" class="txt" name="question[{$i}]" value="{$ques['name']}">
                    <input type="text" class="answer" name="answer[{$i}]" value="{$ques['answer']}" placeholder="请填写题目的答案" onkeyup="value=value.replace(/[^a-dA-D]/g,'');">
                    <input style="display:none" type="checkbox" class="checkd" name="ismulti[{$i}]" id="ismulti_{$i}" value="1" {if condition="$ques['type'] eq 1" }checked{/if} >
                    <input type="hidden" class="hide_qid" name="qid[{$i}]" id="qid[{$i}]" value="{$ques['id']}">
                    <label for="ismulti_{$i}" style="display:none"> 允许多选{$ques['type']}</label>
                    <input type="number" class="point" name="point[{$i}]" value="{$ques['point']}">
                    <select name="ismulti[{$i}]" class="typeselect">
                    <option value="0" {if condition="$ques['type'] eq 0" }selected{/if}>单选</option>
                    <option value="1" {if condition="$ques['type'] eq 1" }selected{/if}>多选</option>
                    <option value="2" {if condition="$ques['type'] eq 2" }selected{/if}>自由填写</option></select>{if condition="$i neq 1"}&nbsp;&nbsp;
                    <a href="javascript:;" class="box_del">删除</a>{/if}
                </p>

                <ul id="{$i}" class="optionul">
                    {volist name="ques['Ranswer']" id="answer" key="k"}
                    <li>
                        <span>A</span><u>选项：</u>
                        <input type="hidden" class="hide_txt" name="oid[{$i}][{$k}]" value="{$answer['id']}">
                        <input type="hidden" class="question" name="oldquestion[{$i}][{$k}]" value="{$answer['question']}">
                        <input type="text" class="txt" name="option[{$i}][{$k}]" value="{$answer['name']}">
                        <a class="list_del" href="javascript:;" title="删除这个选项" style="display: none;">×</a>
                    </li>
                    {/volist}
                </ul>
                <p class="bot_add hidden">
                    <a href="javascript:;" class="btnGrayS vm bigbtn"><i class="Hui-iconfont">&#xe600;</i>再添加一个选项</a>
                </p>
            </div>
            {/volist}
            <p class="add_questio">
                <a href="javascript:;" title="添加" class="btnGrayS vm bigbtn"><i class="Hui-iconfont">&#xe600;</i>再添加一题</a>
            </p>
        </div>

        <ul>
            <ul class="pub_list">
                <li class="bot">
                    <input name="id" value="{$data.id ?? ''}" type="hidden"/>
                    <input type="hidden" value="{$data.cid ?? $addcid}" name="cid"/>
                    {:token()}
                        <input class="btn radius btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                        <input class="btn radius btn-default radius" type="reset" value="&nbsp;&nbsp;重置&nbsp;&nbsp;">
                    <!-- <button onClick="layer_close();" class="btn radius btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button> -->
                </li>
            </ul>
        </ul>

    </form>

</div>

{/block}